{% extends "WebMainSiteBundle:User:layout.html.twig" %}
{% set title = "试卷基本信息" %}
{% block title %}
    {{ title }}
{% endblock %}

{% block user_main %}
    <form class="form-horizontal" method="post" enctype="multipart/form-data" target="msg">
        {% if Exam is defined %}{{ dump(Exam) }}{% endif %}
        {% if Sort is defined %}{{ dump(Sort) }}{% endif %}

        <div class="row">
            <div class="col-md-8">
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="title">试卷类型:</label></div>
                    <div class="col-md-8">
                        <select class="form-control input-lg" name="type">
                            <option value="0" {% if Exam is defined and Exam.type == 0 %} selected="selected" {% endif %}>练习</option>
                            <option value="1" {% if Exam is defined and Exam.type == 1 %} selected="selected" {% endif %}>考试</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="title">试卷标题:</label></div>
                    <div class="col-md-8">
                        <input
                                name="title"
                                id="title"
                                type="text"
                                class="form-control input-lg"
                                placeholder="请设置试卷标题"
                                value="{% if Exam is defined %}{{ Exam.title }}{% endif %}"
                                />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="title">试卷总分:</label></div>
                    <div class="col-md-8">
                        <input
                                name="totalScore"
                                id="totalScore"
                                type="text"
                                class="form-control input-lg"
                                {#placeholder="请设置试卷总分"#}
                                value="{% if Exam is defined %}{{ Exam.totalScore }}{% endif %}"
                                style="width: 60px;"
                                />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="title">考试时间:</label></div>
                    <div class="col-md-8">
                        <input
                                name="totalTime"
                                id="totalTime"
                                type="text"
                                class="form-control input-lg"
                                {#placeholder="请设置考试时间"#}
                                value="{% if Exam is defined %}{{ Exam.totalTime }}{% endif %}"
                                style="width: 60px;"
                                />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="category">试卷分类:</label></div>
                    <div class="col-md-8 sorts">
                        {#["Stage","Grade","Term","Subject","Section","Point"];#}
                        <select  class="form-control input-lg" id="Stage"></select>
                        <select  class="form-control input-lg" id="Grade" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Term" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Subject" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Section" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Point" style="display: none;"></select>
                        {#<select name="category"  class="form-control input-lg">#}
                            {#{% for c in courseCategory %}<option value="{{ c.id }}">{{ c.name }}</option>{% endfor %}#}
                        {#</select>#}
                        <input id="category" name="Point" value="{% if Exam is defined %}{{ Exam.sort }}{% endif %}" type="hidden"/>
                    </div>
                </div>
                {#<div class="form-group">#}
                    {#<div class="col-md-3 text-right"><label class="control-label" for="picCover">封面图片:</label></div>#}
                    {#<div class="col-md-8">#}
                        {#{% include "AssetsUploadBundle:Uploadify:webPic.one.mod.html.twig" with {pic:course["picCover"],name:"picCover"}%}#}
                    {#</div>#}
                {#</div>#}
                {#<div class="form-group">#}
                    {#<div class="col-md-3 text-right"><label class="control-label" for="picMain">试卷主图:</label></div>#}
                    {#<div class="col-md-8">#}
                            {#<div style="width: 160px;height: 160px;display: inline-block;overflow: hidden; position: relative">#}
                                {#&#123;&#35;<a style="position: absolute; z-index: 9999;top:0;left: 0;" href="javascript:rm($(this));">{% if course["picMain"] is defined %}<img src="{{ course["picMain"] }}" width="160" height="160" />{% endif %}</a>&#35;&#125;#}
                                {#<input id="picMain" class="uploadify_upload" type="file"/>#}
                            {#</div>#}
                    {#</div>#}
                {#</div>#}
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="info">要求说明:</label></div>
                    <div class="col-md-8">
                        <textarea  name="intro" class="form-control" rows="11" id="info" placeholder="要求说明">{% if Exam is defined %}{{ Exam.intro }}{% endif %}</textarea>
                    </div>
                </div>
                <p class="buttons-margin-horizontal">
                    <input type="submit" class="btn btn-theme btn-green" value="提交" />
                </p>
            </div>
        </div>
        {#试卷主图：#}
            {#<a href="javascript:rm($(this));">{% if course["picMain"] is defined %}<img src="{{ course["picMain"] }}" width="160" height="160" />{% endif %}</a>#}
        {#<div style="width: 160px;height: 160px;display: inline-block;overflow: hidden;"><input id="picMain" class="uploadify_upload" type="file"/></div>#}
        {#<input type="submit" />#}
    </form>
{% endblock %}


{% block myJs %}
    {#{% include "AssetsUploadBundle:Uploadify:webPic.one.html.twig" %}#}
    {#<script>#}
    {#function rm(a){#}
    {#a.remove();#}
    {#}#}
    {#</script>#}
    {#---------------------------------------分类选择JS------------------------------------#}
    <script>
        function init(){
            $(".sorts").on("change","select", function () {
                var id = $(this).attr("id");
                var find = 0;
                for ( var i in choices ) {

                    if ( find ) {
                        $("#" + choices[i]).html("").hide();
                    }
                    if (choices[i] == id) {
                        find = 1;
                    }
                }

                var parentId = $(this).val();
                setDataById(parentId);
            });
        }
        function emptyData(target){

            $( "#" + target ).hide();
//            $("#" + target).html("");
        }
        function setData(target,id,cnName){
            var option = $('<option>');
            option.val(id).text(cnName);
            $( "#" + target ).append(option);
            $( "#" + target ).show();
        }
        function setDataById(id){
            var data = sorts[id];
//            data[i][0] = id
//            data[i][1] = name
//            data[i][2] = level
//            console.log(data);
            if(data){

                var start = 0;
                for(var i in data){
                    if (!start) {
                        setData(choices[data[i][2]],0,"请选择");
                        start = 1;
                    }
                    setData(choices[data[i][2]],data[i][0],data[i][1]);
                }
            }else {
                $("#category").val(id);
                console.log("目前试卷分类为:" + id);
            }
        }
        $(function () {
            setDataById("0");
            init();
            for( var n in link ){
                console.log(link[n])
                var id = link[n];
                var find = 0;
                for ( var i in choices ) {

                    if ( find ) {
                        $("#" + choices[i]).html("").hide();
                    }
                    if (choices[i] == id) {
                        find = 1;
                    }
                }

                var parentId = link[n];
                setDataById(parentId);

                $("select").find("option[value=" + link[n] + "]").attr("selected","selected");
            }
        });
    </script>
    <script>
        var sorts = {{ sorts|raw }};
        var choices = ["Stage","Grade","Term","Subject","Section","Point"];
        {% if Sort is defined %}var link = {{ Sort|raw }};{% endif %}

    </script>
    {#---------------------------------------分类选择JS------------------------------------#}
{% endblock %}